﻿$(function () {

    var Product = function () { };
    Product.prototype = {
        GetProductDDLByType: function ($ProductType) {
            //根据类型获取简单下拉列表
            var result = "";
            $.ajax({
                type: "post",
                url: "../Handler/ProductHandler.ashx",
                dataType: "json",
                data: { type: 0, ProductType: $ProductType },
                async: false,
                cache: true,
                complete: function () {
                },
                success: function (data) {

                    var str = '<option value="-1">请选择</option>';
                    $(data).each(function (i, e) {
                        str += '<option value="' + e.ProductId + '">' + e.ProductName + '</option>';
                    });
                    result = str;
                    console.log(result);
                }
            });
            return result;
        },
        GetVerifyStatus: function () {
            //得到所有借款审批状态
            var result = "";
            $.ajax({
                type: "post",
                url: "../Handler/VerifyStatusHandler.ashx",
                dataType: "json",
                data: { type: 3 },
                async: false,
                cache: true,
                success: function (data) {
                    var str = '<option value="-1">请选择</option>';
                    $(data).each(function (i, e) {
                        str += '<option value="' + e.VerifyId + '">' + e.VerifyName + '</option>';
                    });
                    result = str;
                    console.log(result);
                }

            });
            return result;
        }
    }

    ////默认绑定产品列表
    var product = new Product();

    var veriftList = product.GetVerifyStatus();
    $(".ddlVerifyStatus").html(veriftList);

    var productList = product.GetProductDDLByType(2);
    $(".ddlProductType").html(productList);

    $("#btnSearch").bind("click", function () {
        var serializer = new JSONSerializer();
        var $formData = serializer.Serialize($("#searchArea"));
        $formData.VerifyStatus = $formData.VerifyStatus == "-1" ? "" : $("#ddlVerifyStatus").find("option:selected").text();
        $formData.Product = $formData.ProductType == "-1" ? "" : $("#ddlProductType").find("option:selected").text();
        $formData.type = 0;
        $.ajax({
            type: "post",
            url: "../Handler/LoanRepHandler.ashx",
            dataType: "json",
            async: false,
            data: $formData,
            success: function (data) {
                if (!data.Status) {
                    alert(data.Message);
                }
            }
        });
    });


});